#import "Menu.h"

@implementation Menu

@synthesize menuId;
@synthesize name;
@synthesize price;
@synthesize description;
@synthesize rank;
@synthesize origPic;
@synthesize thumbPic;
@synthesize onsale;
@synthesize startSaleTime;

+(Menu*)fromString:(NSString *)s{
	SBJsonParser *parser = [SBJsonParser new];
	return [Menu fromJsonObj:[parser objectWithString:s]];
}

-(id)proxyForJson {
	return [NSDictionary dictionaryWithObjectsAndKeys:
			menuId,@"id",
			name,@"name",
			price,@"price",
			description,@"description",
			rank,@"rank",
			origPic,@"origPic",
			thumbPic,@"thumbPic",
			onsale,@"onsale",
			startSaleTime,@"startSaleTime",
			nil];
}

+(Menu*)fromJsonObj:(id)obj{
	Menu* ret=[Menu new];
	id t;

	t=[obj valueForKey:@"id"];
	if(t!=nil) ret.menuId=t;
	else NSLog(@"warning: menu fromJsonObj: missing menu id");

	t=[obj valueForKey:@"name"];
	if(t!=nil) ret.name=(NSString *)t;
	else NSLog(@"warning: menu fromJsonObj: missing menu name");

	t=[obj valueForKey:@"price"];
	if(t!=nil) ret.price=t;
	else NSLog(@"warning: menu fromJsonObj: missing menu price");
	
	t=[obj valueForKey:@"description"];
	if(t!=nil) ret.description=(NSString *)t;
	else NSLog(@"warning: menu fromJsonObj: missing menu description");

	t=[obj valueForKey:@"rank"];
	if(t!=nil) ret.rank=t;
	else NSLog(@"warning: menu fromJsonObj: missing menu rank");

	t=[obj valueForKey:@"origPic"];
	if(t!=nil) ret.origPic=(NSString *)t;
	else NSLog(@"warning: menu fromJsonObj: missing menu origPic");

	t=[obj valueForKey:@"thumbPic"];
	if(t!=nil) ret.thumbPic=(NSString *)t;
	else NSLog(@"warning: menu fromJsonObj: missing menu thumbPic");
	
	t=[obj valueForKey:@"onsale"];
	if(t!=nil) ret.onsale=t;
	else NSLog(@"warning: menu fromJsonObj: missing menu onsale");
	
	t=[obj valueForKey:@"startSaleTime"];
	if(t!=nil) ret.startSaleTime=t;
	else NSLog(@"warning: menu fromJsonObj: missing menu startSaleTime");

	return ret;
}

-(void)dealloc{
	[name release];
	[description release];
	[menuId release];
	[name release];
	[price release];
	[description release];
	[rank release];
	[origPic release];
	[thumbPic release];
	[onsale release];
	[startSaleTime release];
	[super dealloc];
}

@end
